﻿<!--
// PROPERTIES JOOPL SAMPLE

// (c) joopl
// By Matías Fidemraizer (http://www.matiasfidemraizer.com) (http://www.linkedin.com/in/mfidemraizer/en)
// -------------------------------------------------
// http://joopl.codeplex.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jOOPL · Properties sample</title>

    <script type="text/javascript" src="joopl.min.js"></script>
</head>
<body>
    <script type="text/javascript">
        (function () {
            "use strict";

            // #1 Declare a namespace
            $namespace.register("Joopl.Samples", function () {

                // #2 Declare a class "Person" inside the registered namespace.
                // This Person class has some properties defined and some is read-only (continue reading the code!):
                this.Person = $def({
                    // The constructor required an argument "id" (args.id) which is an unique identifier for the Person.
                    $constructor: function (args) {
                        this.$_.name = null;
                        this.$_.secondName = null;
                        this.$_.age = null;
                        this.$_.id = args.id;
                    },

                    $members: {
                        // Here are defined the properties' accessors. There are getters and setters for all of them
                        // excepting "id", which is read-only. jOOPL will generate actual properties automatically (continue reading the code!).
                        get name() {
                            return this.$_.name;
                        },

                        set name(value) {
                            this.$_.name = value;
                        },

                        get secondName() {
                            return this.$_.secondName;
                        },

                        set secondName(value) {
                            this.$_.secondName = value;
                        },

                        get age() {
                            return this.$_.age;
                        },

                        set age(value) {
                            this.$_.age = value;
                        },

                        get id() {
                            return this.$_.id;
                        }
                    }
                });
            });

            // #4 Create a namespace scope in order to have access to the declared class in the registered
            // namespace.
            $namespace.using(["Joopl.Samples"], function () {

                // Since Person.id is read-only, the Person.id must be provided as constructor argument.
                var person = new this.Person({ id: 3893893983 });

                // jOOPL has generated read-write properties based on get_Name, set_Name, get_SecondName and so on.
                person.name = "Matias";
                person.secondName = "Fidemraizer";
                person.age = "28";
                
                document.body.appendChild(
                    // Now it is just about concatenating the values and output them to the document. Person.id is read-only: its value comes from the constructor argument.
                    document.createTextNode(
                        "His name is " + person.name + " " + person.secondName + ", he is " + person.age + " and it has an unique identifier '" + person.id.toString() + "'"
                    )
                );
            });
        })();
    </script>
</body>
</html>
